package icom.acm.manager.mircblog;

import icom.acm.bean.mircblog.T_MB_MESSAGEREPLY;
import icom.acm.util.DBConnect;

import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;

public class T_MB_MessageReplyMgr {	
	public T_MB_MessageReplyMgr(){}
	
	public T_MB_MESSAGEREPLY insert(DBConnect db, T_MB_MESSAGEREPLY mmr) throws MySQLIntegrityConstraintViolationException{		
		String now = icom.acm.util.DateUtil.s_now("yyyy-MM-dd HH:mm:ss");
		String sql = "INSERT INTO T_MB_MESSAGEREPLY" +
			"(MR_ID, MR_U_ID, MR_M_ID, MR_R_ID, MR_MSG, MR_DATE) " +
			"VALUES(NULL, "+mmr.getMR_U_ID()+", " +
			mmr.getMR_M_ID()+", "+ mmr.getMR_R_ID() +
			", '"+mmr.getMR_MSG()+"', '"+now+"')";			
		db.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);						
		db.excute();
		int flag = db.getGeneratedKeys();
		mmr.setMR_ID(flag);
		mmr.setMR_DATE(icom.acm.util.DateUtil.s2d("yyyy-MM-dd HH:mm:ss", now));		
		return mmr;
	}

	public void updateByIdSetRid(DBConnect db, T_MB_MESSAGEREPLY mr) {
		Map<String, Object> arg = new HashMap<String, Object>();
		Map<String, Object> params = new HashMap<String, Object>();
		
		arg.put("MR_R_ID", mr.getMR_R_ID());
		params.put("MR_ID", mr.getMR_ID());
		String sql = mr.toSqlUpdate(arg, params);
		db.prepareStatement(sql);
		db.excuteUpdate();
	}
}


